# 第三方库
from flask import g, session, redirect, url_for, request, flash
from functools import wraps

# 本地模块
from inc.models import AdminMember

def get_current_member():
    """获取当前登录的会员"""
    if 'member_id' in session:
        member = AdminMember.query.get(session['member_id'])
        if member and not member.status:
            # 如果会员被禁用，清除session并重定向到登录页
            session.pop('member_id', None)
            session.pop('member_name', None)
            flash('您的账号已被禁用', 'danger')
            return None
        return member
    return None

def member_login_required(f):
    """登录验证装饰器"""
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if 'member_id' not in session:
            flash('请先登录', 'danger')
            return redirect(url_for('member.auth.login', next=request.url))

        member = get_current_member()
        if not member:
            flash('会员信息无效或已被禁用', 'danger')
            session.pop('member_id', None)
            session.pop('member_name', None)
            return redirect(url_for('member.auth.login'))

        return f(*args, **kwargs)

    return decorated_function

def get_accessible_menus(user_id):
    """获取用户可访问的菜单"""
    # 实现获取菜单逻辑
    pass